def is_prime(x):
    for i in range(2, (x//2)+1):
        if x % i == 0:
            return False
    return True

num = {
    'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
    'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}

a = input().split()
if len(a) != 3 or a[0].isdigit() or a[1].isdigit() or a[2].isdigit():
    print("Wrong input")
else:
    nums = int(''.join(str(num[i]) for i in a))
    nums2 = int(''.join(str(num[i]) for i in a))
    exm = int(''.join(str(num[i]) for i in a))
    while is_prime(nums) == False:
        nums += 1

    while is_prime(nums2) == False:
        nums2 -= 1
    if exm - nums2 > nums - exm:
        print(nums)
    else:
        print(nums2)


